package com.csi.bumblebee.service.impl;

import com.csi.bumblebee.domain.dictionary.Industry;
import com.csi.bumblebee.domain.dictionary.Scale;
import com.csi.bumblebee.mapper.IndustryMapper;
import com.csi.bumblebee.service.IndustryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * industry表
 * @author yeebs
 */
@Service
public class IndustryServiceImpl implements IndustryService {

    @Autowired
    private IndustryMapper industryMapper;

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 根据id查询企业名
     * @param id industry主键id
     * @return industry对象
     */
    @Override
    public Industry findNameById(String id) {
        return industryMapper.findNameById(id);
    }

    /**
     * 根据id查询企业
     * @param id industry主键id
     * @return industry对象
     */
    @Override
    public Industry findById(String id) {
        return industryMapper.findById(id);
    }

    /**
     * 查询所有的一级分类企业类型
     * @return List<Industry>
     */
    @Override
    public List<Industry> listFirst() {

        List<Industry> industryList = (List<Industry>) redisTemplate.opsForValue().get("industryList");

        if (industryList != null) {
            return industryList;
        }else {
            industryList = industryMapper.listFirst();
            redisTemplate.opsForValue().set("industryList", industryList);
            return industryList;
        }
    }
}
